package com.ydj.framework.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.ydj.framework.annotation.AllowGuest;
import com.ydj.framework.annotation.LogPrinter;
import com.ydj.framework.exception.CommonException;
import com.ydj.framework.filter.ExtHttpServletRequest;
import com.ydj.framework.filter.ExtHttpServletResponse;
import com.ydj.framework.module.city.protocol.req.DictCityGetCityByProvinceIdReq;
import com.ydj.framework.module.city.protocol.req.DictCityGetDistrictListByCityIdReq;
import com.ydj.framework.module.city.protocol.req.DictCityGetProvinceListReq;
import com.ydj.framework.module.city.protocol.res.DictCityGetCityByProvinceIdRes;
import com.ydj.framework.module.city.protocol.res.DictCityGetDistrictListByCityIdRes;
import com.ydj.framework.module.city.protocol.res.DictCityGetProvinceListRes;
import com.ydj.framework.module.city.service.DictCityService;
import com.ydj.framework.module.proxy.ProxyUrlService;
import com.ydj.framework.protocol.JsonResult;
import com.ydj.framework.third.screw.ScrewTools;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.io.IOException;

/**
 * @author rick
 */
@Slf4j
@RestController
@RequestMapping("/common")
@Api(tags = "所有项目-公用")
public class FwCommonController {
    @Autowired
    private ScrewTools screwTools;
    @Autowired
    private DictCityService dictCityService;
    @Autowired
    private ProxyUrlService proxyUrlService;

    @AllowGuest
    @ApiOperation(value = "给Nginx检查错误的", hidden = true)
    @GetMapping(value = "/check")
    public void check() {
    }

    @AllowGuest
    @ApiOperation(value = "生成数据库字典")
    @GetMapping(value = "/dict")
    public String dict() throws CommonException {
        return screwTools.make();
    }

    @ApiOperationSupport(order = 11)
    @AllowGuest
    @LogPrinter(response = false)
    @ApiOperation(value = "获取所有省份")
    @PostMapping(value = "/getProvinceList")
    public JsonResult<DictCityGetProvinceListRes> getProvinceList(@RequestBody @Validated DictCityGetProvinceListReq req) {
        DictCityGetProvinceListRes res = dictCityService.getProvinceList(req);
        return JsonResult.success(res);
    }

    @ApiOperationSupport(order = 12)
    @AllowGuest
    @LogPrinter(response = false)
    @ApiOperation(value = "根据省份ID获取城市")
    @PostMapping(value = "/getCityListByProvinceId")
    public JsonResult<DictCityGetCityByProvinceIdRes> getCityListByProvinceId(@RequestBody @Validated DictCityGetCityByProvinceIdReq req) {
        DictCityGetCityByProvinceIdRes res = dictCityService.getCityListByProvinceId(req);
        return JsonResult.success(res);
    }

    @ApiOperationSupport(order = 13)
    @AllowGuest
    @LogPrinter(response = false)
    @ApiOperation(value = "根据城市ID获取区")
    @PostMapping(value = "/getDistrictListByCityId")
    public JsonResult<DictCityGetDistrictListByCityIdRes> getDistrictListByCityId(@RequestBody @Validated DictCityGetDistrictListByCityIdReq req) {
        DictCityGetDistrictListByCityIdRes res = dictCityService.getDistrictListByCityId(req);
        return JsonResult.success(res);
    }
}